<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class UserWithdrawals extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'user_withdrawals';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'type_text',
        'status_text'
    ];

    public function getCreatetimeAttr($value, $data)
    {
        return date('Y-m-d H:i:s', $data['createtime']);
    }


    
    public function getTypeList()
    {
        return ['0' => __('Type 0')];
    }

    public function getStateList()
    {
        return ['0' => __('State 0'), '1' => __('State 1'), '2' => __('State 2')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['state']) ? $data['state'] : '');
        $list = $this->getStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function user()
    {
        return $this->belongsTo(\app\common\model\User::class, 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

}
